var app = getApp();
Page({
    data: {
        requestedAmount: "",
        loanDurationList: ["请选择", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "24", "36"],
        loanDurationIndex: 0,
        mortgageTypeList: ["一抵", "二抵", "一抵转单", "二抵转单"],
        mortgageTypeIndex: 0,
        firstMortgageAmount: "",
        firstMortgageAmountDis: true,
        secondMortgageAmount: "",
        secondMortgageAmountDis: true,
        typeOfFirstMortgageList: ["银行类", "非银行类"],
        typeOfFirstMortgageIndex: 0,
        typeOfFirstMortgageDis: true,
        maritalStatusList: ["未婚", "已婚", "再婚", "离异", "丧偶"],
        maritalStatusIndex: 0,
        mortgagorMaritalStatusIndex: 0,
        mortgagorMaritalStatusDis: true,
        groupList: ["是", "否"],
        groupIndex: 0,
        fullName: "",
        cellphone: "",
        serialNumber: ""
    },
    addLoanDuration: function(e) {
        this.setData({
            loanDurationIndex: e.detail.value
        });
    },
    addMortgageType: function(e) {
        if (e.detail.value == 0) {
            this.setData({
                mortgageTypeIndex: e.detail.value,
                firstMortgageAmountDis: true,
                secondMortgageAmountDis: true,
                typeOfFirstMortgageDis: true
            });
        } else if (e.detail.value == 1) {
            this.setData({
                mortgageTypeIndex: e.detail.value,
                firstMortgageAmountDis: false,
                secondMortgageAmountDis: true,
                typeOfFirstMortgageDis: false
            });
        } else if (e.detail.value == 2) {
            this.setData({
                mortgageTypeIndex: e.detail.value,
                firstMortgageAmountDis: false,
                secondMortgageAmountDis: true,
                typeOfFirstMortgageDis: false
            });
        } else if (e.detail.value == 3) {
            this.setData({
                mortgageTypeIndex: e.detail.value,
                firstMortgageAmountDis: false,
                secondMortgageAmountDis: false,
                typeOfFirstMortgageDis: false
            });
        }
    },
    addTypeOfFirstMortgage: function(e) {
        this.setData({
            typeOfFirstMortgageIndex: e.detail.value
        });
    },
    addMaritalStatus: function(e) {
        this.setData({
            maritalStatusIndex: e.detail.value
        });
    },
    addMortgagorMaritalStatus: function(e) {
        this.setData({
            mortgagorMaritalStatusIndex: e.detail.value
        });
    },
    addGroup: function(e) {
        if (e.detail.value == 0) {
            this.setData({
                groupIndex: e.detail.value,
                mortgagorMaritalStatusDis: true
            });
        } else {
            this.setData({
                groupIndex: e.detail.value,
                mortgagorMaritalStatusDis: false
            });
        }
    },
    onLoad: function(options) {
        this.setData({
            serialNumber: options.serialNumber
        });
        console.log(getCurrentPages());
    },
    wxAppletSubmit: function(e) {
        console.log(e);
        console.log(e.detail.value);
        wx.request({
            url: 'http://localhost:8080/wxAppletOpportunity/wxAppletSubmit',
            data: {
                fullName: e.detail.value.fullName,
                cellphone: e.detail.value.cellphone,
                requestedAmount: e.detail.value.requestedAmount,
                loanDuration: e.detail.value.loanDuration,
                mortgageType: e.detail.value.mortgageType,
                firstMortgageAmount: e.detail.value.firstMortgageAmount,
                secondMortgageAmount: e.detail.value.secondMortgageAmount,
                typeOfFirstMortgage: e.detail.value.typeOfFirstMortgage,
                maritalStatus: e.detail.value.maritalStatus,
                mortgagorMaritalStatus: e.detail.value.mortgagorMaritalStatus,
                serialNumber: "MDT-MNH-ZA4",
                flag: e.detail.value.flag,
                openId: app.globalData.openId
            },
            method: 'POST',
            header: {
                'content-type': 'application/json'
            },
            success: function(res) {               
                wx.navigateTo({
                  url: 'show/show?params=' + JSON.stringify(res.data)
                })
            },
            fail: function(res) {
                console.log("fail");
                console.log(res);
            },
            complete: function(res) {

                console.log("complete");
                console.log(res);
            }
        });
    }
});